package com.kaibes.platform.article.listener;

import java.math.BigInteger;
import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.kaibes.orm.core.listener.InsertListener;
import com.kaibes.orm.curd.Insert;
import com.kaibes.orm.spring.OrmListener;
import com.kaibes.platform.article.db.entity.ArticleComment;
import com.kaibes.platform.article.db.service.ArticleCommentService;
import com.kaibes.platform.article.db.service.ArticleService;

@OrmListener(service = ArticleCommentService.class)
public class ArticleCommentInsertListener implements InsertListener<BigInteger> {
    
    @Autowired
    private ArticleService articleService;

    @Override
    public void afterInsert(Insert insert, List<BigInteger> ids) throws SQLException {
        List<?> dataList = insert.getDatas();
        for (Object object : dataList) {
            ArticleComment target = new ArticleComment();
            BeanUtils.copyProperties(object, target);
            BigInteger articleId = target.getArticleId();
            articleService.plusCommentCount(articleId);
        }
    }
}
